package com.lxyk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.lxyk.mapper.WorkerMapper;
import com.lxyk.pojo.Worker;
import com.lxyk.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName WorkerServiceImpl
 * @Description TODO
 * @Author FJQ
 * @Date 2022/10/24 15:08
 * @Version 1.0
 **/
@Service
public class WorkerServiceImpl implements WorkerService {
    @Autowired
    private WorkerMapper workerMapper;

    @Override
    public List<Worker> listWorker() {
        return workerMapper.selectList(null);
    }

    @Override
    public PageInfo<Worker> listWorker(Worker worker, Integer pageNum, Integer pageSize) {
        List<Worker> workerList = workerMapper.listWorker(worker);
        return new PageInfo<>(workerList);
    }

    @Override
    public PageInfo<Worker> listWorker(Integer pageNum, Integer pageSize) {
        List<Worker> listWorker = workerMapper.selectList(null);
        return new PageInfo<>(listWorker);
    }


    @Override
    public int saveWorker(Worker worker) {
        return workerMapper.insert(worker);
    }

    @Override
    public Worker getWorkerById(Integer wid) {
        QueryWrapper<Worker> qw = new QueryWrapper<Worker>();
        qw.eq("wid",wid);
        return workerMapper.selectOne(qw);
    }

    @Override
    public int updateWorker(Worker worker) {
        QueryWrapper<Worker> qw = new QueryWrapper<>();
        QueryWrapper<Worker> wid = qw.eq("wid", worker.getWid());
        System.out.println(wid);
        return workerMapper.update(worker,qw);
    }

    @Override
    public int addSalary(Integer wid, Integer workerSalary) {
        return workerMapper.addSalary(wid,workerSalary);
    }
}
